package com.burstly.lib.component.networkcomponent.burstly.html.rewards;

import android.annotation.SuppressLint;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.webkit.WebSettings;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import com.burstly.lib.util.LoggerExt;
import com.burstly.lib.util.Utils;

@SuppressLint({"ViewConstructor"})
final class ModalBrowserView extends LinearLayout
  implements View.OnClickListener
{
  private static final LoggerExt LOG = LoggerExt.getInstance();
  private Button mBackButton;
  private LinearLayout mButtonsContainer;
  private Button mCloseButton;
  private View.OnClickListener mCloseListener;
  private Runnable mDestroyCallback;
  private Button mNextButton;
  private Button mOpenExternalButton;
  RewardsView mRewardsView;
  private boolean mShowNavigationControls;

  ModalBrowserView(Context paramContext, String paramString1, String paramString2)
  {
    super(paramContext);
    setOrientation(1);
    createButtons(paramContext);
    layout(paramContext);
    this.mRewardsView.loadDataWithBaseURL(paramString2, paramString1, null, "utf-8", null);
  }

  ModalBrowserView(Context paramContext, String paramString, boolean paramBoolean)
  {
    super(paramContext);
    this.mShowNavigationControls = paramBoolean;
    setOrientation(1);
    createButtons(paramContext);
    layout(paramContext);
    this.mRewardsView.loadUrl(paramString);
  }

  private void createButtons(Context paramContext)
  {
    this.mCloseButton = new Button(paramContext);
    this.mCloseButton.setText("Close");
    this.mCloseButton.setOnClickListener(this);
    if (this.mShowNavigationControls)
    {
      this.mBackButton = new Button(paramContext);
      this.mBackButton.setText("Back");
      this.mBackButton.setOnClickListener(this);
      this.mNextButton = new Button(paramContext);
      this.mNextButton.setText("Forward");
      this.mNextButton.setOnClickListener(this);
      this.mOpenExternalButton = new Button(paramContext);
      this.mOpenExternalButton.setText("Open external");
      this.mOpenExternalButton.setOnClickListener(this);
      return;
    }
    this.mCloseButton.setLayoutParams(new LinearLayout.LayoutParams(Utils.getFillparentValue(), -2));
  }

  private static Animation getFadeInAnimation()
  {
    ScaleAnimation localScaleAnimation = new ScaleAnimation(0.0F, 1.0F, 0.0F, 1.0F, 2, 0.5F, 2, 0.5F);
    localScaleAnimation.setDuration(300L);
    return localScaleAnimation;
  }

  private static Animation getFadeOutAnimation()
  {
    ScaleAnimation localScaleAnimation = new ScaleAnimation(1.0F, 0.0F, 1.0F, 0.0F, 2, 0.5F, 2, 0.5F);
    localScaleAnimation.setDuration(300L);
    return localScaleAnimation;
  }

  private void layout(Context paramContext)
  {
    this.mButtonsContainer = new LinearLayout(paramContext);
    int i = Utils.getFillparentValue();
    this.mButtonsContainer.setLayoutParams(new LinearLayout.LayoutParams(i, -2));
    this.mButtonsContainer.setOrientation(0);
    this.mRewardsView = new RewardsView(paramContext);
    this.mRewardsView.setWebViewClient(new WebViewClient());
    this.mRewardsView.setLayoutParams(new LinearLayout.LayoutParams(i, -2, 1.0F));
    WebSettings localWebSettings = this.mRewardsView.getSettings();
    localWebSettings.setSavePassword(false);
    localWebSettings.setSaveFormData(false);
    localWebSettings.setJavaScriptEnabled(true);
    localWebSettings.setSupportZoom(false);
    localWebSettings.setBuiltInZoomControls(false);
    addView(this.mRewardsView);
    if (this.mShowNavigationControls)
    {
      this.mButtonsContainer.addView(this.mBackButton);
      this.mButtonsContainer.addView(this.mNextButton);
      this.mButtonsContainer.addView(this.mOpenExternalButton, new LinearLayout.LayoutParams(-2, -2, 1.0F));
    }
    addView(this.mButtonsContainer);
    this.mButtonsContainer.addView(this.mCloseButton);
    this.mButtonsContainer.setBackgroundColor(-16777216);
  }

  void destroy()
  {
    if (getAnimation() != null)
    {
      this.mDestroyCallback = new Runnable()
      {
        public void run()
        {
          ModalBrowserView.this.mRewardsView.destroy();
        }
      };
      return;
    }
    this.mRewardsView.destroy();
  }

  RewardsView getRewardsView()
  {
    return this.mRewardsView;
  }

  protected void onAnimationEnd()
  {
    super.onAnimationEnd();
    if (this.mDestroyCallback != null)
    {
      this.mDestroyCallback.run();
      this.mDestroyCallback = null;
    }
  }

  protected void onAttachedToWindow()
  {
    startAnimation(getFadeInAnimation());
    super.onAttachedToWindow();
  }

  public void onClick(View paramView)
  {
    if (paramView == this.mBackButton)
      this.mRewardsView.goBack();
    do
    {
      return;
      if (paramView == this.mNextButton)
      {
        this.mRewardsView.goForward();
        return;
      }
      if ((paramView == this.mCloseButton) && (this.mCloseListener != null))
      {
        clearAnimation();
        startAnimation(getFadeOutAnimation());
        this.mCloseListener.onClick(this);
        return;
      }
    }
    while (paramView != this.mOpenExternalButton);
    try
    {
      Intent localIntent = new Intent("android.intent.action.VIEW", Uri.parse(this.mRewardsView.getUrl()));
      getContext().startActivity(localIntent);
      return;
    }
    catch (ActivityNotFoundException localActivityNotFoundException)
    {
      LOG.logError("ModalBrowserView", localActivityNotFoundException.getMessage(), new Object[0]);
    }
  }

  void setCloseListener(View.OnClickListener paramOnClickListener)
  {
    this.mCloseListener = paramOnClickListener;
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.burstly.html.rewards.ModalBrowserView
 * JD-Core Version:    0.6.2
 */